package org.lztvn.elearning.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.lztvn.elearning.entities.Command;
import org.lztvn.elearning.entities.CommandeLine;



public class CommandLineDaoImpl implements ICommandLineDao{
	@PersistenceContext
	private EntityManager em;
	@Override
	public Long addCommandLine(CommandeLine c) {
		em.persist(c);
		return c.getIdCmdLine();
	}

	@Override
	public void deleteCommandLine(Long idCom) {
		CommandeLine c = em.find(CommandeLine.class, idCom);
		em.remove(c);
	}

	@Override
	public void modifierCommandLine(CommandeLine c) {
		em.merge(c);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CommandeLine> listCommandLine() {
		Query req = em.createQuery("select c from CommandeLine c");
		return req.getResultList();
	}

	@Override
	public List<CommandeLine> listCommandLineByCmdId(Long idCmd, int position, int nb_com) {
		Query req = em.createQuery("select c from CommandeLine c where command = :x");
		req.setParameter("x",idCmd);
//		req.setFirstResult(position);
//		req.setMaxResults(nb_com);
		return req.getResultList();
	}
	
	@Override
	public CommandeLine getCommandLine(Long idCom) {
		return em.find(CommandeLine.class, idCom);
	}

	

}
